OPC Studio User's Guide and Reference
Getting Started with OPC Data Client and OPC Client-Server using PyCharm
Getting Started > Getting Started with OPC Data Client > Getting Started with OPC Data Client in Python > Getting Started with OPC Data Client and OPC Client-Server using PyCharm
In This Topic

Prerequisites

Console Application to Read Value from OPC Unified Architecture Server

  1. On the Welcome to PyCharm screen, press the New Project button.

  2. In the New Project dialog, leave all settings at their defaults, and press the Create button.

  3. If prompted by PyCharm, allow the Microsoft Defender configuration by pressing the Automatically button, and further allowing PyCharm to make corresponding changes to the system.

  4. Switch to the Terminal window of PyCharm, type pip install opclabs_quickopc, and press Enter. Wait until the package is fully installed.

  5. From the PyCharm menu, select File -> New, and then in the New menu, select Python file.

  6. In the New Python file window, type in hello for the Name, and press Enter.

  7. In the hello.py editor tab, add following code:

    import opclabs_quickopc
    from OpcLabs.EasyOpc.UA import *
    
    client = EasyUAClient()
    value = IEasyUAClientExtension.ReadValue(client,
                                             UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer'),
                                             UANodeDescriptor('nsu=http://test.org/UA/Data/;i=10853'))
    print(value)
                                    
    
    You will likely get red squiggles underlining on the OpcLabs namespace in the "from ... import" statement, and on other identifiers further on in the code. Ignore it. This happens because OPC Data Client is based on Python.NET, and the Python IDE cannot recognize the symbols from dynamically imported namespaces.
  8. Select Run -> Run 'hello.py' (Shift+F10) from the PyCharm menu, or press the corresponding button (green right-pointing hollow triangle) on the PyCharm toolbar.

    This will build and launch the program. The value will be read from the OPC server and displayed in the Debug Console window.

Console Application to Read Value from OPC Data Access Server

This Getting Started is for OPC "Classic" (COM/DCOM based). It is supported only on Windows and works with the simulation server installed with OPC Data Client Setup program.

  1. On the Welcome to PyCharm screen, press the New Project button.

  2. In the New Project dialog, leave all settings at their defaults, and press the Create button.

  3. If prompted by PyCharm, allow the Microsoft Defender configuration by pressing the Automatically button, and further allowing PyCharm to make corresponding changes to the system.

  4. Switch to the Terminal window of PyCharm, type pip install opclabs_quickopc, and press Enter. Wait until the package is fully installed.

  5. From the PyCharm menu, select File -> New, and then in the New menu, select Python file.

  6. In the New Python file window, type in helloDA for the Name, and press Enter.

  7. In the helloDA.py editor tab, add following code:

    import opclabs_quickopc
    from OpcLabs.EasyOpc.DataAccess import *
    
    client = EasyDAClient()
    value = IEasyDAClientExtension.ReadItemValue(client, '', 'OPCLabs.KitServer.2', 'Demo.Single')
    print(value)
    
  8. Select Run -> Run 'helloDA.py' (Shift+F10) from the PyCharm menu, or press the corresponding button (green right-pointing hollow triangle) on the PyCharm toolbar.

    This will build and launch the program. The value will be read from the OPC server and displayed in the Debug Console window.

Console Application to Read Value from OPC XML-DA Server

  1. On the Welcome to PyCharm screen, press the New Project button.

  2. In the New Project dialog, leave all settings at their defaults, and press the Create button.

  3. If prompted by PyCharm, allow the Microsoft Defender configuration by pressing the Automatically button, and further allowing PyCharm to make corresponding changes to the system.

  4. Switch to the Terminal window of PyCharm, type pip install opclabs_quickopc, and press Enter. Wait until the package is fully installed.

  5. From the PyCharm menu, select File -> New, and then in the New menu, select Python file.

  6. In the New Python file window, type in helloXml for the Name, and press Enter.

  7. In the helloXml.py editor tab, add following code:

    import opclabs_quickopc
    from OpcLabs.EasyOpc import *
    from OpcLabs.EasyOpc.DataAccess import *
    
    client = EasyDAClient()
    value = IEasyDAClientExtension.ReadItemValue(client,
                                                 ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'),
                                                 DAItemDescriptor('Dynamic/Analog Types/Double'))
    print(value)
                                    
    
  8. Select Run -> Run 'helloXml.py' (Shift+F10) from the PyCharm menu, or press the corresponding button (green right-pointing hollow triangle) on the PyCharm toolbar.

    This will build and launch the program. The value will be read from the OPC server and displayed in the Debug Console window.

See Also

Fundamentals